//
//  ServiceView.m
//  VideoClip
//
//  Created by 赵燕 on 2019/8/28.
//  Copyright © 2019 赵燕. All rights reserved.
//

#import "ServiceView.h"

@interface ServiceView ()

@property(nonatomic,strong) UIView *overlayView;

@end

@implementation ServiceView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView
{
    UIView *overlayView = [[UIView alloc] initWithFrame:self.frame];
    overlayView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.7];
    [self addSubview:overlayView];
    self.overlayView = overlayView;
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = kUIColorFromRGB(0xFFFFFF);
    contentView.layer.cornerRadius = kRatio(10);
    contentView.layer.masksToBounds = YES;
    [overlayView addSubview:contentView];
    contentView.sd_layout
    .centerYEqualToView(overlayView).offset(kRatio(8))
    .centerXEqualToView(overlayView)
    .widthIs(kRatio(308))
    .heightIs(kRatio(347));
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"Service_01"];
    [contentView addSubview:imageView];
    imageView.sd_layout
    .topSpaceToView(contentView, kRatio(0))
    .leftSpaceToView(contentView, kRatio(0))
    .rightSpaceToView(contentView, kRatio(0))
    .heightIs(kRatio(130));
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = kUIColorFromRGB(0x2F54EB);
    titleLabel.text = @"联系客服";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont systemFontOfSize:kRatio(20) weight:100];
    [contentView addSubview:titleLabel];
    titleLabel.sd_layout
    .centerXEqualToView(contentView)
    .topSpaceToView(imageView, kRatio(30))
    .heightIs(kRatio(21));
    
    [titleLabel setSingleLineAutoResizeWithMaxWidth:kScreenWidth];
    
    UILabel *titleLabel1 = [[UILabel alloc] init];
    titleLabel1.textColor = kUIColorFromRGB(0x595959);
    titleLabel1.text = @"客服电话：0851-88921869";
    titleLabel1.textAlignment = NSTextAlignmentLeft;
    titleLabel1.font = [UIFont systemFontOfSize:kRatio(16)];
    [contentView addSubview:titleLabel1];
    titleLabel1.sd_layout
    .leftSpaceToView(contentView, kRatio(55))
    .topSpaceToView(titleLabel, kRatio(20))
    .heightIs(kRatio(17));
    
    [titleLabel1 setSingleLineAutoResizeWithMaxWidth:kScreenWidth];
    
    UILabel *titleLabel2 = [[UILabel alloc] init];
    titleLabel2.textColor = kUIColorFromRGB(0x595959);
    titleLabel2.text = @"客服  QQ: 3399411909";
    titleLabel2.textAlignment = NSTextAlignmentLeft;
    titleLabel2.font = [UIFont systemFontOfSize:kRatio(16)];
    [contentView addSubview:titleLabel2];
    titleLabel2.sd_layout
    .leftSpaceToView(contentView, kRatio(55))
    .topSpaceToView(titleLabel1, kRatio(6))
    .heightIs(kRatio(17));
    
    [titleLabel2 setSingleLineAutoResizeWithMaxWidth:kScreenWidth];
    
    UIButton *okBtn = [[UIButton alloc]init];
    [okBtn setTitle:[NSString stringWithFormat:@"OK"] forState:UIControlStateNormal];
    [okBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [okBtn setBackgroundColor:kUIColorFromRGB(0x2F54EB)];
    okBtn.layer.cornerRadius = 5;
    okBtn.layer.masksToBounds = YES;
    [contentView addSubview:okBtn];
    [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(contentView.mas_bottom).offset(kRatio(-30));
        make.width.mas_equalTo(kRatio(248));
        make.centerX.equalTo(contentView.mas_centerX);
        make.height.mas_equalTo(kRatio(47));
    }];
}

- (void)dismiss
{
    [UIView animateWithDuration:0.25 animations:^{
        for (UIView *subView in self.subviews) {
            if ([subView isEqual:self.overlayView]) {
                continue;
            }
            CGRect deafultRect = subView.frame;
            deafultRect.origin.y = CGRectGetHeight(self.frame);
            subView.frame = deafultRect;
        }
    } completion:^(BOOL finished) {
        for (UIView *subView in self.subviews) {
            [subView removeFromSuperview];
        }
        [self removeFromSuperview];
    }];
}
@end
